from game.ai.ai_state import *

#in this state, a character will move to a specific tile in the level
class MoveState(AiState):
    def __init__(self, ch, dst, path, **args):
        AiState.__init__("move", **args)
        self.ch = ch
        self.dst = dst
        self.path = path

    def update(self, dat):
        if self.dst is None or self.path is None:
            return 1

        i, dst = self.path.pop()
        px, py = self.ch.x, self.ch.y
        rdst = [dst.x - px, dst.y - py]
        dat.act_mgr.perform("move", dat, self.ch.pos(), [rdst])
        #if the destintation is reached or no movement was taken (blocked)
        if len(self.path) == 0 or (px == self.ch.x and py == self.ch.y):
            return 1

        return 0